﻿Imports System.Data.OleDb
Public Class ReciepeEntry
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            If String.IsNullOrEmpty(Session("UserId").ToString) Then
                Response.Redirect("Login.aspx")
            End If

        Catch ex As Exception
            Response.Redirect("Login.aspx")
        End Try
        
    End Sub

    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click
        Dim objBl = New BL()
        ''Dim objDal = New DL()
        Try
            Dim filename As String
            If fpPic.HasFile Then

                Dim ImageExtention As String = fpPic.FileName.Substring(fpPic.FileName.LastIndexOf("."), 4)
                If ImageExtention = ".jpg" Or ImageExtention = ".JPG" Or ImageExtention = ".gif" Or ImageExtention = ".GIF" Then
                    filename = System.DateTime.Now.Millisecond.ToString() & "_" & fpPic.PostedFile.FileName
                    fpPic.SaveAs(Server.MapPath("foodImage/" & filename))

                    Dim dbconn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & Server.MapPath("/App_Data/KitchenCompition.mdb"))
                    Dim strInsert As String = "Insert into Reciepe(Name,Email,RecipeName,Recipe,Price,UserId,Pic,typesofBiryani,Duration) Values("
                    strInsert += "'" & txtName.Text & "',"
                    strInsert += "'" & txtEmail.Text & "',"
                    strInsert += "'" & txtRecipeName.Text & "',"
                    strInsert += "'" & txtRecipe.Text & "',"
                    strInsert += ddlPrice.SelectedItem.Value & ","
                    strInsert += Session("UserId").ToString & ","
                    strInsert += "'" & "foodImage/" & filename & "',"
                    strInsert += "'" & ddltypeRecipe.SelectedItem.Value & "',"
                    strInsert += "'" & ddlDurationHr.SelectedItem.Value & ":" & ddlDurationMin.SelectedItem.Value & "')"

                    objBl.GetInsertUpdate(strInsert, dbconn)
                    Response.Redirect("myRecipe.aspx")
                Else
                    lbMessageError.Text = "The extension of Image should be Jpg and gif"
                End If
            Else
                lbMessageError.Text = "Image file mendontory"
            End If
        Catch ex As Exception
            lbMessageError.Text = ex.Message
        End Try
        
        

    End Sub
End Class